package com.fast.fastenjoy.base.utils;

import org.springframework.context.ApplicationContext;

public class ApplicationContextUtils {

	private static ApplicationContext context;
	
	public static void setApplicationContext(ApplicationContext context){
		if(context != null){
			ApplicationContextUtils.context = context;
		}
	}

	public static ApplicationContext getContext() {
		return context;
	}
	
	public static Object getBean(String beanName){
		
		ApplicationContext ac = getContext();
		
		return ac != null ? ac.getBean(beanName) : null;
	}
	
	public static <T> T getBean(Class<T> clazz){
		
		ApplicationContext ac = getContext();
		
		return ac != null ? ac.getBean(clazz) : null;
	}
	
	public static <T> T getBean(String beanName, Class<T> clazz){
		
		ApplicationContext ac = getContext();
		
		return ac != null ? ac.getBean(beanName, clazz) : null;
	}
	
}
